import java.sql.Connection;
import java.sql.DriverManager;
import java.util.concurrent.Callable;

// 按两次 Shift 打开“随处搜索”对话框并输入 `show whitespaces`，
// 然后按 Enter 键。现在，您可以在代码中看到空格字符。

import java.io.IOException;
import java.sql.*;

public class sh {
    public static void main(String[] args) throws ClassNotFoundException{

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbc","root","120513");
            String sql = "select * from user";
            PreparedStatement ps = conn.prepareStatement(sql);//预处理SQL语句；
            ResultSet rs = ps.executeQuery();//执行SQL语句；
            while(rs.next()){
                int id = rs.getInt("id");
                String name = rs.getString("name");
                int  age= rs.getInt("age");
                System.out.println("id:"+id+",name:"+name+",age:"+age);
            }
        }
        catch(SQLException e){
            System.out.println(e);
        }
    }
}


